#include "HelloWorldScene.h"
#include "Global.h"
#include "OrbitSystem/OrbitSystem.h"
#include "Circle/CircleSegment.h"
#include "LevelManager/LevelManager.h"
#include "Circle/Circle.h"
#include "Bullet/BulletManager.h"
#include "GameScript/OnTapToFire.h"
#include "PhysicSystem/PhysicManager.h"

USING_NS_CC;

CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( s_pPathResCirclePList.filePath , s_pPathResCirclePng.filePath );
	
	OrbitManager::sharedOrbitManager()->setContentSize( visibleSize );

	LevelManager* level = new LevelManager();
	level->initWithFile("Level/Level_Template.xml");

	delete level;

	this->addChild( OrbitManager::sharedOrbitManager() );

	BulletManager::sharedBulletManager()->init( );
	BulletManager::sharedBulletManager()->getBullet( );

	this->addChild( BulletManager::sharedBulletManager() );

	OnTapToFire* pScript = new OnTapToFire( );

	BulletManager::sharedBulletManager()->addChild( pScript );

	pScript->release( );

	PhysicManager::sharedPhysicManager()->scheduleUpdate( );

	this->addChild( PhysicManager::sharedPhysicManager() );

    return true;
}


void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    CCDirector::sharedDirector()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}
